package c.d.a.a.i;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.RectF;
import c.d.a.a.b.h;
import c.d.a.a.b.h.a;
import c.d.a.a.j.b;
import c.d.a.a.j.c;
import c.d.a.a.j.d;
import c.d.a.a.j.f;
import c.d.a.a.j.g;
import java.util.List;
import java.util.Objects;

/* compiled from: XAxisRenderer */
public class k extends a {
    public h h;
    public Path i = new Path();
    public float[] j = new float[2];
    public RectF k = new RectF();
    public float[] l = new float[2];
    public RectF m = new RectF();
    public float[] n = new float[4];
    public Path o = new Path();

    public k(c.d.a.a.j.h hVar, h hVar2, f fVar) {
        super(hVar, fVar, hVar2);
        this.h = hVar2;
        this.e.setColor(-16777216);
        this.e.setTextAlign(Align.CENTER);
        this.e.setTextSize(g.d(10.0f));
    }

    public void a(float f, float f2, boolean z) {
        if (this.a.b() > 10.0f && !this.a.c()) {
            float f3;
            double d;
            f fVar = this.c;
            RectF rectF = this.a.b;
            c b = fVar.b(rectF.left, rectF.top);
            f fVar2 = this.c;
            RectF rectF2 = this.a.b;
            c b2 = fVar2.b(rectF2.right, rectF2.top);
            if (z) {
                f3 = (float) b2.b;
                d = b.b;
            } else {
                f3 = (float) b.b;
                d = b2.b;
            }
            float f4 = (float) d;
            c.d.c(b);
            c.d.c(b2);
            f = f3;
            f2 = f4;
        }
        super.b(f, f2);
        c();
    }

    public void b(float f, float f2) {
        super.b(f, f2);
        c();
    }

    public void c() {
        String c = this.h.c();
        Paint paint = this.e;
        Objects.requireNonNull(this.h);
        paint.setTypeface(null);
        this.e.setTextSize(this.h.d);
        b b = g.b(this.e, c);
        float f = b.b;
        float a = (float) g.a(this.e, "Q");
        Objects.requireNonNull(this.h);
        b g = g.g(f, a, 0.0f);
        h hVar = this.h;
        Math.round(f);
        Objects.requireNonNull(hVar);
        h hVar2 = this.h;
        Math.round(a);
        Objects.requireNonNull(hVar2);
        this.h.A = Math.round(g.b);
        this.h.B = Math.round(g.c);
        b.d.c(g);
        b.d.c(b);
    }

    public void d(Canvas canvas, float f, float f2, Path path) {
        path.moveTo(f, this.a.b.bottom);
        path.lineTo(f, this.a.b.top);
        canvas.drawPath(path, this.d);
        path.reset();
    }

    public void e(Canvas canvas, String str, float f, float f2, d dVar, float f3) {
        Paint paint = this.e;
        float fontMetrics = paint.getFontMetrics(g.k);
        paint.getTextBounds(str, 0, str.length(), g.j);
        float f4 = 0.0f - ((float) g.j.left);
        float f5 = (-g.k.ascent) + 0.0f;
        Align textAlign = paint.getTextAlign();
        paint.setTextAlign(Align.LEFT);
        if (f3 != 0.0f) {
            f4 -= ((float) g.j.width()) * 0.5f;
            f5 -= fontMetrics * 0.5f;
            if (!(dVar.b == 0.5f && dVar.c == 0.5f)) {
                b g = g.g((float) g.j.width(), fontMetrics, f3);
                f -= (dVar.b - 0.5f) * g.b;
                f2 -= (dVar.c - 0.5f) * g.c;
                b.d.c(g);
            }
            canvas.save();
            canvas.translate(f, f2);
            canvas.rotate(f3);
            canvas.drawText(str, f4, f5, paint);
            canvas.restore();
        } else {
            if (!(dVar.b == 0.0f && dVar.c == 0.0f)) {
                f4 -= ((float) g.j.width()) * dVar.b;
                f5 -= fontMetrics * dVar.c;
            }
            canvas.drawText(str, f4 + f, f5 + f2, paint);
        }
        paint.setTextAlign(textAlign);
    }

    public void f(Canvas canvas, float f, d dVar) {
        Objects.requireNonNull(this.h);
        Objects.requireNonNull(this.h);
        int i = this.h.m * 2;
        float[] fArr = new float[i];
        for (int i2 = 0; i2 < i; i2 += 2) {
            fArr[i2] = this.h.k[i2 / 2];
        }
        this.c.f(fArr);
        for (int i3 = 0; i3 < i; i3 += 2) {
            float f2 = fArr[i3];
            if (this.a.i(f2)) {
                String a = this.h.d().a(this.h.k[i3 / 2]);
                Objects.requireNonNull(this.h);
                e(canvas, a, f2, f, dVar, 0.0f);
            }
        }
    }

    public RectF g() {
        this.k.set(this.a.b);
        this.k.inset(-this.b.h, 0.0f);
        return this.k;
    }

    public void h(Canvas canvas) {
        h hVar = this.h;
        if (hVar.a && hVar.s) {
            float f = hVar.c;
            this.e.setTypeface(null);
            this.e.setTextSize(this.h.d);
            this.e.setColor(this.h.e);
            d b = d.b(0.0f, 0.0f);
            h hVar2 = this.h;
            a aVar = hVar2.C;
            if (aVar == a.TOP) {
                b.b = 0.5f;
                b.c = 1.0f;
                f(canvas, this.a.b.top - f, b);
            } else if (aVar == a.TOP_INSIDE) {
                b.b = 0.5f;
                b.c = 1.0f;
                f(canvas, (this.a.b.top + f) + ((float) hVar2.B), b);
            } else if (aVar == a.BOTTOM) {
                b.b = 0.5f;
                b.c = 0.0f;
                f(canvas, this.a.b.bottom + f, b);
            } else if (aVar == a.BOTTOM_INSIDE) {
                b.b = 0.5f;
                b.c = 0.0f;
                f(canvas, (this.a.b.bottom - f) - ((float) hVar2.B), b);
            } else {
                b.b = 0.5f;
                b.c = 1.0f;
                f(canvas, this.a.b.top - f, b);
                b.b = 0.5f;
                b.c = 0.0f;
                f(canvas, this.a.b.bottom + f, b);
            }
            d.d.c(b);
        }
    }

    public void i(Canvas canvas) {
        a aVar = a.BOTH_SIDED;
        h hVar = this.h;
        if (hVar.r && hVar.a) {
            this.f.setColor(hVar.i);
            this.f.setStrokeWidth(this.h.j);
            Paint paint = this.f;
            Objects.requireNonNull(this.h);
            paint.setPathEffect(null);
            a aVar2 = this.h.C;
            if (aVar2 == a.TOP || aVar2 == a.TOP_INSIDE || aVar2 == aVar) {
                RectF rectF = this.a.b;
                float f = rectF.left;
                float f2 = rectF.top;
                canvas.drawLine(f, f2, rectF.right, f2, this.f);
            }
            aVar2 = this.h.C;
            if (aVar2 == a.BOTTOM || aVar2 == a.BOTTOM_INSIDE || aVar2 == aVar) {
                RectF rectF2 = this.a.b;
                float f3 = rectF2.left;
                float f4 = rectF2.bottom;
                canvas.drawLine(f3, f4, rectF2.right, f4, this.f);
            }
        }
    }

    public void j(Canvas canvas) {
        h hVar = this.h;
        if (hVar.q && hVar.a) {
            int save = canvas.save();
            canvas.clipRect(g());
            if (this.j.length != this.b.m * 2) {
                this.j = new float[(this.h.m * 2)];
            }
            float[] fArr = this.j;
            for (int i = 0; i < fArr.length; i += 2) {
                float[] fArr2 = this.h.k;
                int i2 = i / 2;
                fArr[i] = fArr2[i2];
                fArr[i + 1] = fArr2[i2];
            }
            this.c.f(fArr);
            this.d.setColor(this.h.g);
            this.d.setStrokeWidth(this.h.h);
            Paint paint = this.d;
            Objects.requireNonNull(this.h);
            paint.setPathEffect(null);
            Path path = this.i;
            path.reset();
            for (int i3 = 0; i3 < fArr.length; i3 += 2) {
                d(canvas, fArr[i3], fArr[i3 + 1], path);
            }
            canvas.restoreToCount(save);
        }
    }

    public void k(Canvas canvas) {
        List list = this.h.t;
        if (list != null && list.size() > 0) {
            float[] fArr = this.l;
            fArr[0] = 0.0f;
            fArr[1] = 0.0f;
            for (int i = 0; i < list.size(); i++) {
                if (((c.d.a.a.b.g) list.get(i)).a) {
                    int save = canvas.save();
                    this.m.set(this.a.b);
                    this.m.inset(-0.0f, 0.0f);
                    canvas.clipRect(this.m);
                    fArr[0] = 0.0f;
                    fArr[1] = 0.0f;
                    this.c.f(fArr);
                    float[] fArr2 = this.n;
                    fArr2[0] = fArr[0];
                    RectF rectF = this.a.b;
                    fArr2[1] = rectF.top;
                    fArr2[2] = fArr[0];
                    fArr2[3] = rectF.bottom;
                    this.o.reset();
                    Path path = this.o;
                    float[] fArr3 = this.n;
                    path.moveTo(fArr3[0], fArr3[1]);
                    path = this.o;
                    fArr3 = this.n;
                    path.lineTo(fArr3[2], fArr3[3]);
                    this.g.setStyle(Style.STROKE);
                    this.g.setColor(0);
                    this.g.setStrokeWidth(0.0f);
                    this.g.setPathEffect(null);
                    canvas.drawPath(this.o, this.g);
                    canvas.restoreToCount(save);
                }
            }
        }
    }
}
